package com.h2cloud.threadPool;

import java.util.Timer;
import java.util.concurrent.*;

/**
 * @Package: com.h2cloud.threadPool
 * @ClassName: Main1
 * @Author: h2cloud
 * @CreateTime: 2021/10/18 10:47 上午
 * @Description:
 */
public class Main1 {
    public static void main(String[] args) {
        // 创建一个固定大小的线程池:
        ExecutorService es = Executors.newFixedThreadPool(4);
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
                4, 10,
                60L, TimeUnit.SECONDS,
                new SynchronousQueue<>());

        for (int i = 0; i < 6; i++) {
            es.submit(new Task("" + i));
        }
        // 关闭线程池:
        es.shutdown();
    }
}

class Task implements Runnable {
    private final String name;

    public Task(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        System.out.println("start task " + name);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        System.out.println("end task " + name);
    }
}
